<style lang="less">
    .page_style {
        margin-top: 10px;
        text-align: right;
    }
    .item1{
        height: 42px;
        line-height: 40px;
    }
    .actionBtn{
        margin-left: 10px;
    }
    .code {
        width: 300px;
        margin-left: 10px;
    }
    .sousuo{
        margin-left: 10px;
    }
</style>
<template>
    <wl-content-top>
        <template slot="header">
            <Form>
                <FormItem>
                    <FormItem>
                        <span class="name">项目名称：</span>
                        <Input v-model="project_name" placeholder="请输入项目名称" class="code"/>
                        <Button type="success" v-model="project_name" @click="selectBySelectObj"
                                class="sousuo">
                            <Icon type="ios-search"/>
                            搜索
                        </Button>
                    </FormItem>
                </FormItem>
            </Form>
        </template>
        <template slot="body">
            <div>
        <Tabs  v-model="tab_index" @on-click="changeTab">
            <TabPane v-for="(item, index) in tabDataList" :key="index" :label="item.label" :name="item.value">
                <div style="margin-top: 20px">
                    <Table border :columns="columns1" :data="datalist">
                        <template slot-scope="{ row }" slot="action">
                            <Button type="info" size="small" class="actionBtn" @click="show(row)">详情</Button>
                            <Button type="primary" size="small" class="actionBtn" @click="authenticat(row)"
                                    v-if="row.log_state ===  '1' || row.log_state ===  '6' || row.log_state ===  '11' || row.log_state ===  '4'
                            || row.log_state ===  '9' || row.log_state ===  '14'">审核</Button>
                            <Button type="warning" size="small" class="actionBtn" @click="Reason(row)" v-if="row.log_state ===  '2'
                            || row.log_state ===  '4' || row.log_state ===  '7' || row.log_state ===  '9'
                            || row.log_state ===  '12' ||row.log_state ===  '14'">驳回原因</Button>
                        </template>
                    </Table>
                </div>
            </TabPane>
        </Tabs>
                <div class="page_style">
                    <Page show-total :current="currentPageNo" :page-size="currentPageSize"
                          :total="pageObj.totalRecord" @on-change="getPageNo"/>
                </div>
            </div>
        <Modal v-model="modal" title="详情" width="700" cancel-text="关闭"
               @on-ok="cancel" @on-cancel="cancel" ok-text="确定" style="position:relative;">
            <Form ref="paramData" :model="paramData2"  >
                <Row class="item1">
                    <Col span="6" style="text-align: right" class="">项目名称:</Col>
                    <Col span="12" offset="1">{{paramData2.log_project_name}}</Col>
                </Row>
                <Row class="item1">
                    <Col span="6" style="text-align: right" class="">项目编号:</Col>
                    <Col span="12" offset="1">{{paramData2.log_project_code}}</Col>
                </Row>
                <Row class="item1">
                    <Col span="6" style="text-align: right" class="">所属机构:</Col>
                    <Col span="12" offset="1">{{paramData2.log_report_mechanism}}</Col>
                </Row>
                <Row class="item1">
                    <Col span="6" style="text-align: right" class="">项目描述:</Col>
                    <Col span="12" offset="1">{{paramData2.log_data}}</Col>
                </Row>
            </Form>
        </Modal>
        <Modal v-model="modal1" title="上传资料" width="700" cancel-text="关闭"
               @on-ok="okUpload" @on-cancel="modal1 = false" ok-text="确定" style="position:relative;">
            <Form ref="paramData" :model="paramData2"  >
                <Row class="item1">
                    <Col span="5" style="text-align: center" class="">上传文件:</Col>
                    <Col span="16">
                        <Upload
                                multiple
                                :before-upload="beforeUpload"
                                action="https://txy.juyouhx.com/Api/Api/upBase64ToOss">
                            <Button icon="ios-cloud-upload-outline">上传图片</Button>
                            <div></div>
                        </Upload>
                    </Col>
                </Row>
                <Row class="item1" style="height:auto">
                    <Col span="5" style="text-align: center" class="">项目描述:</Col>
                    <Col span="12">
                        <Input v-model="project_data" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder=""></Input>
                    </Col>
                </Row>
            </Form>
        </Modal>
                <Modal v-model="updateModal" title="认证资料" width="500" cancel-text="驳回"
                        ok-text="通过" style="position:relative;">
                <Row>
                    <Col span="5" style="text-align: center" class="">上传文件:</Col>
                    <Col style="margin-top: -9px">
                        <Upload action="http://dlqt.juyouhx.com/Api/Api/ObjectToOss"
                                :on-success="bbb"
                                :format="['pdf']"
                                :on-format-error="handleFormatError">
                            <Button icon="ios-cloud-upload-outline">点击上传</Button>
                        </Upload>
                    </Col>
                </Row>
                <Row>
                    <Col span="5" style="text-align: center" class="">文字描述:</Col>
                    <Col span="12">
                        <Input v-model="miaoshu" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder=""></Input>
                    </Col>
                </Row>
                <div slot="footer" style="display: inline;padding-left: 5px">
                    <Button type="primary" size="large" @click="insert1">保存</Button>
                </div>
                <div slot="footer" style="display: inline;padding-left: 5px">
                    <Button type="primary" size="large" @click="adopt">提交</Button>
                </div>
                <div slot="footer" style="display: inline;padding-left: 5px">
                    <Button type="primary" size="large"  @click="start1">驳回</Button>
                </div>
                <div slot="footer" style="display: inline;padding-left: 5px">
                    <Button type="primary" size="large"  @click="updateModal=false">关闭</Button>
                </div>
            </Modal>
            <Modal v-model="besouse" title="驳回原因" width="500" ok-text="驳回" cancel-text="取消" @on-ok="back" @on-cancel="cancel1">
                <Row>
                    <Col span="5" style="text-align: center" class="">驳回原因:</Col>
                    <Col span="12">
                        <Input v-model="writebesouse" type="textarea" :autosize="{minRows: 2,maxRows: 5}" placeholder="请输入驳回原因"></Input>
                    </Col>
                </Row>
            </Modal>
        </template>
    </wl-content-top>
</template>

<script>
// import { date2str } from '@/api/enterprise'
import { createConsultFile, getProjectCompanyList, updateStateAdopt, updateStateUnadopt, insertProjectFile, selectProjectValue } from '@/api/demo'
/* import Col from 'iview/src' */
// upBase64
export default {
  /* components: { Col }, */
  data () {
    return {
      writebesouse: '', // 驳回原因
      besouse: false,
      result1: {},
      url1: '', // 上传文件地址
      miaoshu: '',
      paramData3: {},
      companyCode: '',
      projectId: '',
      projectState: '',
      project_data: '',
      cId: '',
      pId: '',
      Fstate: '',
      updateModal: false,
      modal: false,
      modal1: false,
      modal2: false,
      modal6: false,
      pic_preview_mol: false,
      modal_loading: false,
      currentPageNo: 1,
      currentPageSize: 10,
      project_name: '',
      project_state: '0',
      dateTime: '',
      tab_index: '0',
      pageObj: {
        pageNo: 1,
        pageSize: 10,
        state: ''
      },
      searchInfo: {
        project_id: '',
        project_name: ''
      },
      paramData2: {},
      paramData: {},
      datalist: [],
      descData: ['待咨询', '待企业咨询', '企业咨询驳回', '企业咨询通过', '咨询驳回', '咨询通过(待验收)', '待企业验收', '企业验收驳回', '企业验收驳通过', '验收驳回', '验收通过(待评估)', '待企业评估', '企业评估驳回', '企业评估通过', '评估驳回', '评估通过'],
      tabDataList: [
        { label: '咨询类', value: '0' },
        { label: '验收类', value: '1' },
        { label: '评估类', value: '2' }
      ],
      columns1: [
        {
          title: '序号',
          type: 'index',
          width: 160,
          align: 'center'
        },
        {
          title: '项目名称',
          key: 'log_project_name',
          align: 'center',
          width: 240
        },
        {
          title: '项目编号',
          key: 'log_project_code',
          align: 'center',
          width: 180
        },
        {
          title: '所属机构',
          key: 'log_report_mechanism',
          align: 'center',
          width: 230
        },
        {
          title: '项目状态',
          key: 'state',
          align: 'center',
          width: 150,
          render: (h, params) => {
            let log_state = params.row.log_state
            return h('span', this.descData[log_state])
          }
        },
        {
          title: '操作',
          slot: 'action',
          width: 240,
          align: 'center'
        }
      ]
    }
  },
  methods: {
    cancel () {
      this.besouse = false
    },
    start1 () {
      this.besouse = true
    },
    bbb (file) {
      this.url1 = file.url
    },
    insert1 () {
      let a = { project_id: this.paramData3.log_project_id, state: this.tab_index, data: this.miaoshu, upload_file: this.url1, project_state: this.tab_index }
      insertProjectFile(a).then(ret => {
        if (ret.data.data.count !== 1) {
        } else {
          this.$Message.error({
            content: '操作失败'
          })
          this.updateModal = false
        }
      })
    },
    del () {

    },
    handleFormatError () {
      this.$Notice.warning({
        title: '文件格式不正确',
        desc: '文件格式不正确,请选择pdf.'
      })
    },
    show (row) {
      this.modal = true
      this.paramData2 = row
    },
    // 通过
    go () {
      let data = {
        project_state: this.tab_index,
        upload_file: this.url1,
        state: this.paramData3.log_state,
        id: this.paramData3.log_project_id,
        data: this.miaoshu,
        project_id: this.paramData3.log_project_id
      }
      updateStateAdopt(data).then(ret => {
        if (ret.data.errcode === 0) {
          console.log(ret)
          this.findList()
          this.updateModal = false
        } else {
          this.$Message.error({
            content: '操作失败,\n' + ret.data.errmsg
          })
        }
      })
    },
    Reason (row) {
      let text = ''
      console.log(row, 'pppp')
      switch (row.log_state) {
        case '2':
          text = row.log_enterprise_consulting_back_resaon
          break
        case '4':
          text = row.log_consulting_back_resaon
          break
        case '7':
          text = row.log_enterprise_acceptance_back_resaon
          break
        case '9':
          text = row.log_acceptance_back_resaon
          break
        case '12':
          text = row.log_enterprise_assessment_back_resaon
          break
        case '14':
          text = row.log_assessment_back_resaon
          break
      }
      this.$Modal.warning({
        title: '驳回原因：',
        content: text
      })
    },
    // 驳回
    back () {
      /*      let data = {
        id: this.projectId,
        state: this.projectState
      } */
      let data = {
        project_state: this.tab_index,
        reason: this.writebesouse,
        data: this.miaoshu,
        upload_file: this.url1,
        state: this.paramData3.log_state,
        id: this.paramData3.log_project_id,
        project_id: this.paramData3.log_project_id
      }
      updateStateUnadopt(data).then(ret => {
        if (ret.data.errcode === 0) {
          console.log(ret)
          this.findList()
          this.besouse = false
          this.updateModal = false
        } else {
          this.$Message.error({
            content: '操作失败,\n' + ret.data.errmsg
          })
        }
      })
    },
    reject () {
      if (confirm('是否确定驳回？')) {
        this.back()
      }
    },
    adopt () {
      if (confirm('是否确定通过？')) {
        this.go()
      }
    },
    // 认证弹出对话框
    authenticat (row) {
      /* this.projectId = id
      this.projectState = state */
      this.miaoshu = ''
      this.url1 = ''
      this.paramData3 = row
      console.log(this.paramData3)
      let c = { project_id: this.paramData3.log_project_id, state: this.tab_index }
      selectProjectValue(c).then(ret => {
        this.result1 = ret.data.data
        this.miaoshu = this.result1.data
        this.url1 = this.result1.upload_file
      })
      this.updateModal = true
    },
    // 列表初始化
    findList () {
      let data = {
        company_id: '4ebb43d0-0140-11ea-b529-0242ac110028',
        project_state: this.project_state,
        project_id: this.searchInfo.project_id,
        project_name: this.searchInfo.project_name
      }
      this.datalist = []
      getProjectCompanyList(data).then(ret => {
        if (ret.data.errcode === 0) {
          if (ret.data.errcode === 0) {
            this.datalist = ret.data.data.results
            console.log(ret)
            this.pageObj.totalRecord = ret.data.data.totalRecord
          } else {
            this.$Message.error({
              content: '操作失败,\n' + ret.data.errmsg
            })
          }
        }
      })
    },
    selectBySelectObj () {
      let data = {
        project_state: this.tab_index,
        pageNo: 1,
        pageSize: 10,
        project_name: this.project_name,
        company_id: '4ebb43d0-0140-11ea-b529-0242ac110028' }
      getProjectCompanyList(data).then(ret => {
        this.datalist = ret.data.data.results
        console.log(this.project_name, 'ddd')
      })
    },
    edit (pId, cId, fState) {
      this.pId = pId
      this.cId = cId
      this.Fstate = fState
      this.modal1 = true
    },
    okUpload () {
      if (confirm('是否确定上传？')) {
        this.createFile()
      }
    },
    // 上传图片之前转base64
    beforeUpload (file) {
      let that = this
      const reader = new FileReader()
      reader.readAsDataURL(file)
      reader.onload = () => {
        let index = reader.result.indexOf('base64,') + 7
        console.log(reader.result.substring(index))
        that.paramData2.file_upload_file = reader.result.substring(index)
        that.createFile(that.paramData2.file_upload_file)
      }
      return false
    },
    // 上传资料
    createFile () {
      // upBase64(userCardInfo.Base64Photo).then(data => {
      //   console.log(userCardInfo.Base64Photo)
      //   console.log(data)
      // })
      let data = {
        project_id: this.pId,
        company_id: this.cId,
        state: this.tab_index,
        upload_file: this.paramData2.file_upload_file,
        data: this.project_data
      }
      console.log(data)
      createConsultFile(data).then(ret => {
        console.log(ret.data)
        if (ret.data.errcode === 0) {
          this.$Modal.success({
            title: '成功',
            content: '上传成功'
          })
          this.project_data = ''
        } else {
          this.$Modal.error({
            title: '失败',
            content: '上传失败'
          })
        }
      })
    },
    getPageNo (pageNo) {
      this.pageObj.pageNo = pageNo
      this.getProjectCompanyList()
    },
    // 条件搜索
    findConsult () {
      if (this.tab_index === '0') {
        this.project_state = 0
        this.findList()
      } else if (this.tab_index === '1') {
        this.project_state = 1
        this.findList()
      } else if (this.tab_index === '2') {
        this.project_state = 2
        this.findList()
      }
    },
    cancel1 () {
      this.modal = false
      this.paramData2 = {}
    },
    ok111 () {

    },
    // 切换tab页
    changeTab () {
      this.currentPageNo = 1
      this.currentPageSize = 10
      if (this.tab_index === '0') {
        this.searchInfo = {}
        this.project_state = '0'
        this.findList()
      } else if (this.tab_index === '1') {
        this.searchInfo = {}
        this.project_state = '1'
        this.findList()
      } else if (this.tab_index === '2') {
        this.searchInfo = {}
        this.project_state = '2'
        this.findList()
      }
    }
  },
  mounted () {
    this.findList()
  }
}
</script>

<style scoped>

</style>
